﻿using System;
using System.Collections.Generic;

using Nextensions.Text;

namespace Nextensions.Net.HTML
{
    internal class ElementFactory<T> where T: Element
    {
        public static void CreateChildElements(Element Parent, params Tags[] TagList)
        {
            //Dictionary<string,T> dict = new Dictionary<string,T>();

            foreach (Tags el in TagList)
            {
                bool closing = el == Tags.Input ? false : true;
                List<string> elementHTMLs = MLUtil.GetNodeText(Parent.HTML, el.ToString(), closing);

                foreach (string element in elementHTMLs)
                {
                    T instance = (T)Activator.CreateInstance(typeof(T), element);
                    Parent.AddElement(instance);

                    //if (!dict.ContainsKey(instance.Name)) // Radio multiple radio buttons may have the same name
                    //dict.Add(instance.Name, instance);
                }
            }
        }
    }
}
